package com.weclud.api.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.weclud.model.common.AjaxResult;
import com.weclud.model.wechat.Categories;
import com.weclud.model.wechat.IndexImages;
import com.weclud.model.wechat.Notices;
import com.weclud.service.IConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * 微信小程序配置接口
 */
@Api(value = "ConfigController ")
@RestController
@RequestMapping("/config")
public class ConfigController {

    private final Logger logger = LoggerFactory.getLogger(ConfigController.class);

    @Autowired
    private IConfigService configService;

    @ApiOperation(value = "功能目录")
    @PostMapping("/categories")
    public AjaxResult getCategories() {
        logger.info("获取功能目录");
        List<Categories> list = configService.getAllCategories();
        JSONArray array = JSONArray.parseArray(JSON.toJSONString(list));
        return AjaxResult.success(array);
    }

    @ApiOperation(value = "主页轮播图片")
    @PostMapping("/index")
    public AjaxResult getIndexImages() {
        List<IndexImages> list = configService.getIndexImages();
        JSONArray array = JSONArray.parseArray(JSON.toJSONString(list));
        return AjaxResult.success(array);
    }

    @ApiOperation(value = "通知")
    @PostMapping("/notice")
    public AjaxResult getNotice() {
        List<Notices> list = configService.getNotices();
        JSONArray array = JSONArray.parseArray(JSON.toJSONString(list));
        return AjaxResult.success(array);
    }

    @Api(value = "AdminUserController ")
    @RestController
    @RequestMapping("/admin/user")
    public class RestApi {
        /**
         * 用户登录
         */
        @ApiOperation(value = "登录")
        @ApiImplicitParams({@ApiImplicitParam(name = "userName", value = "用户名", required = true, dataType = "String"),
                @ApiImplicitParam(name = "password", value = "密码", required = true, dataType = "String")})
        @GetMapping("/login")
        public AjaxResult login(String userName, String password){
            return AjaxResult.success(userName+password);
        }
    }


}
